package com.younion.action.consumer.impl;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.younion.action.consumer.AbstractRequestConsumer;
import com.younion.action.interactive.mobile.ApiConstant;
import com.younion.action.interactive.mobile.ResultObject;
import com.younion.business.IMemberCardService;
import com.younion.model.MyCardDeleteResult;
import com.younion.util.HttpRequestUtils;
import com.younion.util.JsonUtils;

public class MyCardDeleteConsumer extends AbstractRequestConsumer {

	private IMemberCardService memberCardService;

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return deleteMyCard(request, response);
	}

	public String deleteMyCard(HttpServletRequest request,
			HttpServletResponse response) {
		MyCardDeleteResult myCardDeleteResult = new MyCardDeleteResult();
		String card_id = request.getParameter("card_id");
		ResultObject resultObject = new ResultObject();
		try {
			List ids = new ArrayList();
			ids.add(card_id);
			memberCardService.remove(ids);
			myCardDeleteResult.setSuccessful("1");
			resultObject.setStatus(ApiConstant.SUCCESS_STATUS);

		} catch (Exception e) {
			myCardDeleteResult.setSuccessful("0");
			resultObject.setStatus(ApiConstant.FALSE_STATUS);
			resultObject.setMsg(ApiConstant.PUBLIC_EXCEPTION);
			e.printStackTrace();
		}
		resultObject.setResult(myCardDeleteResult);
		HttpRequestUtils.printContent(JsonUtils.parseObj2Json(resultObject),
				response);
		return null;
	}

	public void setMemberCardService(IMemberCardService memberCardService) {
		this.memberCardService = memberCardService;
	}
}
